#ifndef __CFGPARSER_H__
#define __CFGPARSER_H__

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include <iostream>
#include <string>
#include <vector>

/*use our own profile.h to parse the configure*/
#define OWN_PROFILE 

#ifdef OWN_PROFILE
	#include "profile.h"
#else
	#include <confuse.h>
#endif
	
using namespace std;

class CfgParser {
public:
	CfgParser();
	~CfgParser();
#ifdef OWN_PROFILE
	bool Initialize(const string& file_path );
#else
	bool Initialize(cfg_opt_t* opts,const string& file_path );
#endif
	bool Update();

	bool GetBool( const string& item );
	int  GetInt( const string& item );

	string GetStr( const string& item);
	vector<string> GetList( const string& item);

private:
	void SetCfgPath(const string & file_path);
	int GetCfgStat();
	bool CfgParse();
	bool GetKey( const string& item , string& secname );
	bool GetSessName(const string& item , string& secname );
private:
#ifdef OWN_PROFILE
	CProfile * cfg;
#else
	cfg_t *cfg;
#endif
	string cfg_fpath;
	struct stat cfg_stat;
//	pthread_rwlock_t cfg_lock;
};
#endif
